import request from '@/utils/request'
import {parseStrEmpty} from "@/utils/ruoyi";

// 查询列表
export function list(baseurl, query) {
  return request({
    url: `${baseurl}list`,
    method: 'get',
    params: query,
  })
}

// 查询列表
export function recycle(baseurl, query) {
  return request({
    url: `${baseurl}recycle`,
    method: 'get',
    params: query,
  })
}

// 查询总数
export function count(baseurl, query) {
  return request({
    url: `${baseurl}count`,
    method: 'get',
    params: query,
  })
}

// 查询字典选择
export function dict(baseurl, query) {
  return request({
    url: `${baseurl}dict`,
    method: 'get',
    params: query,
    headers: {
      isToken: true
    }
  })
}

// 查询详细信息
export function getInfo(baseurl, id) {
  return request({
    url: `${baseurl}getById/${parseStrEmpty(id)}`,
    method: 'get',
  })
}

export function getOne(baseurl, query) {
  return request({
    url: `${baseurl}getOne`,
    method: 'get',
    params: query,
  })
}

// 查询详细信息
export function checkExist(baseurl, query) {
  return request({
    url: baseurl + 'exists',
    method: 'get',
    params: query,
    headers: {
      isToken: true,
    }
  })
}

// 新增信息
export function save(baseurl, data) {
  return request({
    url: baseurl,
    method: 'post',
    data: data
  })
}

// 修改信息
export function update(baseurl, data) {
  return request({
    url: baseurl,
    method: 'put',
    data: data
  })
}

// 删除
export function remove(baseurl, id, batchFlag) {
  batchFlag = batchFlag === undefined ? false : batchFlag
  return request({
    url: `${baseurl}${batchFlag ? 'batch/' : ''}${id}`,
    method: 'delete'
  })
}

// 彻底删除
export function clear(baseurl, id, batchFlag) {
  batchFlag = batchFlag === undefined ? false : batchFlag
  return request({
    url: `${baseurl}remove/${batchFlag ? 'batch/' : ''}${id}`,
    method: 'delete'
  })
}

// 清空回收站
export function clean(baseurl) {
  return request({
    url: `${baseurl}clean`,
    method: 'delete'
  })
}

// 撤销删除
export function restore(baseurl, id, batchFlag) {
  batchFlag = batchFlag === undefined ? false : batchFlag
  return request({
    url: `${baseurl}restore/${batchFlag ? 'batch/' : ''}${id}`,
    method: 'post',
  })
}
